#include "Txl.h"

struct Person
{
    int id;
    char *Name;
    char *Phone;
};

Per* CreatePer(int id,const char* name,const char* phone)
{
    Per *s = (Per*)malloc(sizeof(Per));
    if(s == NULL)
    {
        printf("Create malloc error\n");
        exit(-1);
    }
    s->id = id;
    s->Name = strdup(name);
    s->Phone = strdup(phone);
    return s;
}

void ClearPer(void *p)
{
    Per *s = (Per*)p;
    free(s->Name);
    free(s->Phone);
    free(s);
    //printf("清理\n");
}

//回调函数
void PrintPer(void *p)
{
    Per *s = (Per*)p;
    printf("序号:%d\n姓名:%s  号码:%s\n",s->id,s->Name,s->Phone);
}

bool IsNameEqual(void *p1,void *p2)
{
    Per *s = (Per*)p1;
    const char *name = (const char*)p2;
    return strcmp(s->Name,name) == 0;
}

bool IsPhoneEqual(void *p1,void *p2)
{
    Per *s = (Per*)p1;
    const char *phone = (const char*)p2;
    return strcmp(s->Phone,phone) == 0;
}

bool IsIDEqual(void *p1,void *p2)
{
    Per *s = (Per*)p1;
    long id = (long)p2;
    return s->id == id;
}